home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / FALCON / ACC / OUTLINE.ACC / CACHE.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  15.7 KB  |  585 lines

  1. /* ===================================================================
  2.  * FILE: CACHE.C
  3.  * ===================================================================
  4.  * DATE: December 9, 1992
  5.  * 
  6.  * DESCRIPTION: Fonts ACC
  7.  *
  8.  * This file handles the Cache settings dialog box.
  9.  *
  10.  * COMPILER: TURBO C Version 2.0
  11.  */
  12.  
  13.  
  14. /* INCLUDE FILES
  15.  * ===================================================================
  16.  */
  17. #include <sys\gemskel.h>
  18. #include <tos.h>
  19. #include <linea.h>
  20. #include <string.h>
  21. #include <stdio.h>
  22.  
  23. #include "country.h"
  24. #include "fonthead.h"
  25. #include "fonts.h"
  26. #include "mainstuf.h"
  27. #include "text.h"
  28. #include "fsmio.h"
  29. #include "mover.h"
  30. #include "front.h"
  31. #include "ptbind.h"
  32. #include "extend.h"
  33. #include "lex.h"
  34. #include "fileio.h"
  35. #include "status.h"
  36.  
  37.  
  38.  
  39.  
  40. /* STRUCTURES
  41.  * ===================================================================
  42.  */
  43.  
  44.  
  45. /* EXTERN
  46.  * ===================================================================
  47.  */
  48. extern int AES_Version;
  49. extern Token lookahead;
  50.  
  51.  
  52.  
  53. /* PROTOTYPES
  54.  * ===================================================================
  55.  */
  56. void    DoCache( void );
  57. int    HandleCache( int button, WORD *msg );
  58.  
  59. void    Get_Default_Cache( void );
  60. void    Calc_Cache( BOOLEAN draw );
  61. long    limits( long num, long min_num, long max_num );
  62. void    Up_Down_Arrow( int obj, int UpButton, char *text, long *num, int NBase );
  63. void    DoValuesCheck( void );
  64.  
  65.  
  66.  
  67. /* DEFINES
  68.  * ===================================================================
  69.  */
  70. #define SPEEDO_PERCENT_MIN    1    /* 10% Speedo CACHE/BITMAP */
  71. #define SPEEDD_PERCENT_MAX    9    /* 90% Speedo CACHE/BITMAP */
  72. #define MAX_CACHE_SIZE    99999L
  73. #define MIN_CACHE_SIZE    10L
  74. #define MIN_CHAR_CACHE_SIZE 1L
  75.  
  76.  
  77. /* GLOBALS
  78.  * ===================================================================
  79.  */
  80. char    cache_path[ 128 ];
  81. char    data_cache_text[ 6 ];    /* Unused Miscellaneous Cache Text */
  82. char    bitmap_cache_text[6];    /* Unused Character Cache Text     */
  83.  
  84. long    dcache_size;    /* actual usage of the data and bitmap cache */
  85. long    bcache_size;    /* in KBYTES....                 */
  86.  
  87. char    CharSizeText[6];    /* Character Cache Text */
  88. char    MiscSizeText[6];    /* Miscellaneous Cache Text */
  89. char    BitSizeText[6];        /* Bitmap Size Text */
  90. long    OldBitMapSize;
  91.  
  92. int    OldPercent;        /* Speedo Percent...*/
  93. int    CurPercent;
  94. long    OldSpeedoCache;        /* Old Speedo Cache Size */
  95. long    ccache;            /* Character Cache Size */
  96. long    mcache;            /* Miscellaneous Cache Size */
  97. long    old_ccache;
  98. long    old_mcache;
  99.  
  100. long    CurUsage;
  101. char    CurSizeText[6];
  102.  
  103. /* FUNCTIONS
  104.  * ===================================================================
  105.  */
  106.  
  107.  
  108. /* DoCache()
  109.  * ===================================================================
  110.  */
  111. void
  112. DoCache( void )
  113. {
  114.    long extra;
  115.    long interim;
  116.    
  117.     Reset_Tree( ad_cache );
  118.  
  119.    /* ------------------------------------------------------
  120.     * Handle the Cache I/O Boxes and the Unused Cache...
  121.     * ------------------------------------------------------
  122.     */
  123.     Enable( LCACHE );
  124.     Enable( MCACHE );
  125.     Enable( SCACHE );
  126.     Enable( CCACHE );
  127.     MakeExit( LCACHE );
  128.     MakeExit( MCACHE );
  129.     MakeExit( SCACHE );
  130.     MakeExit( CCACHE );
  131.    
  132.     Enable( CUTITLE );
  133.     Enable( CUNUSED );
  134.     Enable( MUTITLE );
  135.     Enable( MUNUSED );
  136.     
  137.     dcache_size = bcache_size = 0L;
  138.     sprintf( data_cache_text, "%5ldK", dcache_size );
  139.     TedText( MUNUSED ) = data_cache_text;
  140.  
  141.     /* Character Cache */   
  142.     sprintf( bitmap_cache_text, "%5ldK", bcache_size );
  143.     TedText( CUNUSED ) = bitmap_cache_text;
  144.     
  145.     if( !SpeedoFlag )
  146.     {
  147.        Disable( LCACHE );
  148.        Disable( MCACHE );
  149.        Disable( SCACHE );
  150.        Disable( CCACHE );
  151.        NoExit( LCACHE );
  152.        NoExit( MCACHE );
  153.        NoExit( SCACHE );
  154.        NoExit( CCACHE );
  155.        
  156.        Disable( CUTITLE );
  157.        Disable( CUNUSED );
  158.        Disable( MUTITLE );
  159.        Disable( MUNUSED );
  160.     }    
  161.     else
  162.       Calc_Cache( FALSE );
  163.  
  164.  
  165.    /* ------------------------------------------------------
  166.     * Handle the Cache Sizes...
  167.     * ------------------------------------------------------
  168.     */
  169.    OldPercent  = CurPercent = Current.speedo_percent;
  170.    OldSpeedoCache = Current.SpeedoCacheSize;
  171.    
  172.    /* Set the Speedo Character Cache */   
  173.    interim = Current.speedo_percent * Current.SpeedoCacheSize;
  174.    extra   = ( interim % 10L ) > 5L;
  175.    ccache  = ( interim / 10L ) + extra;
  176.    
  177.    ccache = limits( ccache, MIN_CHAR_CACHE_SIZE, MAX_CACHE_SIZE );       
  178.    old_ccache = ccache;
  179.    sprintf( CharSizeText,"%5ld", ccache );
  180.    TedText( CSIZE ) = CharSizeText;
  181.  
  182.    /* Display a size based on a percentage of the Misc CACHE Size */
  183.    interim  =  (10L - (long)Current.speedo_percent ) * Current.SpeedoCacheSize;
  184.    extra    = ( interim % 10L ) > 5L;
  185.    mcache   = ( interim / 10L ) + extra;
  186.    mcache    = limits( mcache, MIN_CACHE_SIZE, MAX_CACHE_SIZE );       
  187.    old_mcache = mcache;
  188.    sprintf( MiscSizeText, "%5ld", mcache );
  189.    TedText( MSIZE ) = MiscSizeText;
  190.  
  191.  
  192.    /* Set the Bitmap Font Cache */
  193.    Current.BitMapCacheSize = limits( Current.BitMapCacheSize, 0L, MAX_CACHE_SIZE );       
  194.    OldBitMapSize = Current.BitMapCacheSize;
  195.    sprintf( BitSizeText,"%5ld", Current.BitMapCacheSize );
  196.    TedText( BSIZE ) = BitSizeText;
  197.  
  198.  
  199.    /* Handle Getting the Current Minimum Amount of Miscellanous Required */
  200.    CurUsage = GetCurUsage();
  201.    sprintf( CurSizeText, "%5ldK", CurUsage );
  202.    TedText( CACHEMIN ) = CurSizeText;
  203.    
  204.    Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); 
  205. }
  206.  
  207.  
  208.  
  209. /* HandleCache()
  210.  * ===================================================================
  211.  */
  212. int
  213. HandleCache( int button, WORD *msg )
  214. {
  215.    int   quit;
  216.    int     out;   
  217.    int   error;
  218.         
  219.    quit   = FALSE;
  220.  
  221.    
  222.    /* Handle Double-clicking of the objects */   
  223.    if( ( button != -1 ) && ( button & 0x8000 ) )
  224.       button &= 0x7FFF;
  225.    
  226.    switch( button )
  227.    {
  228.      case CCANCEL: Current.SpeedoCacheSize = OldSpeedoCache;
  229.            Current.speedo_percent  = OldPercent;
  230.            Current.BitMapCacheSize = OldBitMapSize;
  231.    
  232.      case COK:    Deselect( button );
  233.                if( button == COK )
  234.                {
  235.                   DoValuesCheck();
  236.              CacheCheck();
  237.                }
  238.                
  239.             Reset_Tree( ad_options );     
  240.           Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); 
  241.                break;
  242.  
  243.      case LCACHE:
  244.      case MCACHE:
  245.      case SCACHE:  if( SpeedoFlag )
  246.                 {
  247.                   sprintf( cache_path, "%s\\", OutlinePath );
  248.                                     
  249.                   out = fsel_name( FALSE, cache_path, "*.SPC", cache_text[ button - LCACHE ] );
  250.             
  251.                   if( ( ( out == A_OK ) || ( out == A_CANCEL )) && ( cache_path[0] != '\0' ) )
  252.                   { 
  253.                      if( out == A_OK )
  254.                      {
  255.                         /* Check if the file exists first */
  256.                     if(( button == LCACHE ) || ( button == MCACHE ))
  257.                         {
  258.                   olddma = Fgetdta();    
  259.                   Fsetdta( &newdma );        /* Point to OUR buffer */
  260.  
  261.                   error = Fsfirst( cache_path, 0 );/* Normal file search for 1st file */
  262.                   if( error != E_OK )    /* No such files! */
  263.                    { 
  264.                     Fsetdta( olddma );    /* Point to OLD buffer */
  265.                     form_alert( 1, nofile );       
  266.                     XDeselect( tree, button );
  267.                     return( quit );        
  268.                   }
  269.                         }
  270.                      
  271.                         if( open_vwork() )
  272.                         {
  273.                           switch( button )
  274.                           {
  275.                              case LCACHE: out = v_loadcache( vhandle, cache_path, TRUE );
  276.                                         break;
  277.                                       
  278.                              case MCACHE: out = v_loadcache( vhandle, cache_path, FALSE ); /* append, merge */
  279.                                          break;
  280.                                        
  281.                              case SCACHE: out = v_savecache( vhandle, cache_path );
  282.                                         break;
  283.                              default:
  284.                                       break;
  285.                            }
  286.                            if( out == -1 )
  287.                                   form_alert( 1, alert19 );
  288.                            close_vwork();
  289.  
  290.                          }
  291.                          else
  292.                           form_alert( 1, alert18 );
  293.                      }
  294.              }
  295.              Calc_Cache( TRUE );
  296.             } 
  297.                 XDeselect( tree, button );
  298.                  break;
  299.                  
  300.      case CCACHE:   if( SpeedoFlag )
  301.                  {
  302.                     if( form_alert( 1, alert17 ) == 1 )
  303.                     {
  304.                       if( open_vwork())
  305.                       {
  306.                          if( v_flushcache( vhandle ) == -1 )
  307.                              form_alert( 1, alert19 );    
  308.                          close_vwork();
  309.                       }
  310.                       else
  311.                          form_alert( 1, alert18 );
  312.                  Calc_Cache( TRUE );
  313.                    }  
  314.                  }  
  315.                  XDeselect( tree, button );
  316.                  break;
  317.  
  318.  
  319.      case MUP:
  320.      case MDOWN:    Up_Down_Arrow( button, MUP, &MiscSizeText[0], &mcache, MSIZE );
  321.                  break;
  322.  
  323.      case BUP:
  324.      case BDOWN:    Up_Down_Arrow( button, BUP, &BitSizeText[0], &Current.BitMapCacheSize, BSIZE );
  325.             break;
  326.  
  327.      case CUP:
  328.      case CDOWN:    Up_Down_Arrow( button, CUP, &CharSizeText[0], &ccache, CSIZE );
  329.             break;
  330.  
  331.      default:     if( button == -1 )
  332.               {
  333.                 switch( msg[0] )
  334.                 {
  335.                   case WM_REDRAW: 
  336.                                break;
  337.                                    
  338.                   case AC_CLOSE:  quit = TRUE;
  339.                                break;
  340.                                        
  341.                   case WM_CLOSED: quit = TRUE;
  342.                      DoValuesCheck();
  343.                                CloseWindow();
  344.                      break;
  345.  
  346.              case CT_KEY:
  347.                           break;
  348.                   default:
  349.                           break;
  350.                 }
  351.               }
  352.               break;
  353.    }
  354.    return( quit );
  355.  
  356.  
  357. }
  358.  
  359.  
  360.  
  361.  
  362. /* Get_Default_Cache()
  363.  * ======================================================================
  364.  */
  365. void
  366. Get_Default_Cache( void )
  367. {
  368.     int  out;
  369.     int  error;
  370.     char Drive;
  371.     long len;
  372.             
  373.     if( SpeedoFlag )
  374.     {
  375.        /* Get the Bootup Device */
  376.        strcpy( ExtendPath, "C:\\EXTEND.SYS" );
  377.        Drive = GetBaseDrive();
  378.        ExtendPath[0] = Drive;   
  379.  
  380.        olddma = Fgetdta();    
  381.        Fsetdta(&newdma);        /* Point to OUR buffer  */
  382.  
  383.        xopen( ExtendPath );    /* Find the extend.sys file and open it*/
  384.        if( !errno )        /* WE have an EXTEND.SYS and need to */
  385.        {            /* look for the font path         */
  386.        
  387.          lookahead = NO_TOKEN;
  388.          if( !match(PATH) )
  389.          {
  390.         /* Error: No Path line at the top of the extend.sys file
  391.          * Therefore, we don't load any default.fsm file.
  392.          */
  393.         xclose();
  394.             Fsetdta(olddma);        /* Point to OLD buffer */
  395.         return;     
  396.          }
  397.          skipequal();
  398.  
  399.          if( match(PATHSPEC) )
  400.          {
  401.         strncpy( OutlinePath, yytext, yyleng );
  402.         len = yyleng-1;
  403.         if( OutlinePath[len] != '\\' ) ++len;
  404.           OutlinePath[len] = '\0';
  405.         if( len > 2 )    /* below code fails for items like 'f:'*/
  406.         {
  407.            if( !stat( OutlinePath, &statbuf) )
  408.               errno = (isdir(&statbuf)) ? 0 : ENOTDIR;
  409.            if( errno )
  410.            {
  411.               /* Error Parsing the path */    
  412.               xclose();
  413.                   Fsetdta(olddma);        /* Point to OLD buffer */
  414.               return;
  415.            }
  416.         }  
  417.          }
  418.          
  419.          xclose();
  420.          Fsetdta(olddma);        /* Point to OLD buffer */
  421.  
  422.          strcat( OutlinePath, "\\DEFAULT.SPC" );
  423.          error = Fopen( OutlinePath, 0 );
  424.      if ( error < 0 )        /* No such files! */
  425.            return;            
  426.  
  427.      Fclose( error );    /* Close the file immediately */       
  428.      
  429.          if( open_vwork() )
  430.          {
  431.             out = v_loadcache( vhandle, OutlinePath, TRUE );
  432.             if( out == -1 )    /* Cache I/O Error! */
  433.              form_alert( 1, alert19 );      
  434.  
  435.             close_vwork();
  436.          }  /* error opening a workstation, no cache loaded..*/   
  437.          else
  438.             form_alert( 1, alert18 );
  439.             
  440.        }/* NO EXTEND.SYS, NO default cache */
  441.    }
  442. }
  443.  
  444.  
  445. /* Calc_Cache()
  446.  * ======================================================================
  447.  * Calculates and inquires the current size available of the 
  448.  * Speedo Data cache and the Speedo bitmap cache.
  449.  */
  450. void
  451. Calc_Cache( BOOLEAN draw )
  452. {
  453.    if( SpeedoFlag )
  454.    {
  455.    
  456.      if( open_vwork() )
  457.      {
  458.        vqt_cachesize( vhandle, 1, &dcache_size );
  459.        vqt_cachesize( vhandle, 0, &bcache_size );
  460.        dcache_size /= 1024L;
  461.        bcache_size /= 1024L;     
  462.        close_vwork();
  463.      }
  464.      else
  465.      {
  466.        form_alert( 1, alert18 );
  467.        dcache_size = bcache_size = 0L;
  468.      }
  469.      /* Miscellaneous Cache */  
  470.      sprintf( data_cache_text, "%5ldK", dcache_size );
  471.      TedText( MUNUSED ) = data_cache_text;
  472.  
  473.      /* Character Cache */   
  474.      sprintf( bitmap_cache_text, "%5ldK", bcache_size );
  475.      TedText( CUNUSED ) = bitmap_cache_text;
  476.    
  477.      if( draw )
  478.      {
  479.        Objc_draw( tree, CUNUSED, MAX_DEPTH, NULL );
  480.        Objc_draw( tree, MUNUSED, MAX_DEPTH, NULL );
  481.      }
  482.    }
  483. }
  484.  
  485.  
  486. /* limits()
  487.  * ====================================================================
  488.  */
  489. long
  490. limits( long num, long min_num, long max_num )
  491. {
  492.     if( num > max_num )
  493.             num = max_num;
  494.         
  495.     if( num < min_num )
  496.             num = min_num;
  497.     return( num );    
  498. }
  499.  
  500.  
  501.  
  502. /* Up_Down_Arrow()
  503.  * ====================================================================
  504.  * Handle the up and down arrow presses in the outline font dialog
  505.  * for the cache settings.
  506.  */
  507. void
  508. Up_Down_Arrow( int obj, int UpButton, char *text, long *num, int NBase )
  509. {
  510.    MRETS mk;
  511.    long  min_cache;
  512.    
  513.    XSelect( tree, obj );
  514.  
  515.    *num = atol( text );
  516.    min_cache = (( UpButton == BUP ) ? ( 0L ) : ( MIN_CACHE_SIZE ) );   
  517.    
  518.    if( UpButton == CUP )
  519.       min_cache = MIN_CHAR_CACHE_SIZE;   
  520.    
  521.    *num = limits( *num, min_cache, MAX_CACHE_SIZE );
  522.    do
  523.    {
  524.       Evnt_timer( 50L );
  525.    
  526.       
  527.       if( obj == UpButton )
  528.          *num = (((*num + 1) > MAX_CACHE_SIZE ) ? ( MAX_CACHE_SIZE ) : ( *num + 1 ) );
  529.       else
  530.          *num = (((*num - 1) < min_cache ) ? ( min_cache ) : ( *num - 1 ) );
  531.  
  532.       sprintf( text, "%5ld", *num );
  533.       Objc_draw( tree, NBase, MAX_DEPTH, NULL );
  534.       Graf_mkstate( &mk );
  535.       
  536.    }while( mk.buttons );
  537.    
  538.    XDeselect( tree, obj );
  539. }
  540.  
  541.  
  542.  
  543. /* DoValuesCheck()
  544.  * ====================================================================
  545.  */
  546. void
  547. DoValuesCheck( void )
  548. {
  549.    long  half;
  550.    int   extra;
  551.  
  552.    /* Speedo Character Stuff */               
  553.    ccache = atol( CharSizeText );
  554.    if( !ccache )
  555.       ccache = old_ccache;
  556.    ccache = limits( ccache, MIN_CHAR_CACHE_SIZE, MAX_CACHE_SIZE );       
  557.  
  558.    /* Speedo Miscellaneous Stuff */
  559.    mcache = atol( MiscSizeText );
  560.    if( !mcache )
  561.        mcache = old_mcache;
  562.    mcache = limits( mcache, MIN_CACHE_SIZE, MAX_CACHE_SIZE );       
  563.  
  564.    /* Get Speedo Cache Size */
  565.    Current.SpeedoCacheSize = ccache + mcache;
  566.            
  567.    /* Get Percent Value */
  568.    Current.speedo_percent = 0;
  569.    half     =  Current.SpeedoCacheSize / 2L;
  570.    extra    =  ((( ccache * 10L ) % Current.SpeedoCacheSize) > half );
  571.    CurPercent =  (int)(( ccache * 10L ) / Current.SpeedoCacheSize);
  572.    Current.speedo_percent = CurPercent + extra;
  573.    Current.speedo_percent = (int)limits( (int)Current.speedo_percent, 1L, 9L );       
  574.                 
  575.    /* Get BitMap Cache Size */
  576.    Current.BitMapCacheSize = atol( BitSizeText );
  577.    Current.BitMapCacheSize = limits( Current.BitMapCacheSize, 0L, MAX_CACHE_SIZE );       
  578.  
  579.    /* A Real Change has occurred, so set change flag */
  580.    if( ( Current.SpeedoCacheSize != OldSpeedoCache ) ||
  581.        ( Current.speedo_percent  != OldPercent ) ||
  582.        ( Current.BitMapCacheSize != OldBitMapSize ) )
  583.        SetChangeFlag();
  584. }
  585.